package cn.com.ddapp.ddm.adapter;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.com.ddapp.ddm.R;
import cn.com.ddapp.ddm.api.OKUtilAPI;
import cn.com.ddapp.ddm.bean.GoodSmallSortBean;
import cn.com.ddapp.ddm.util.TDevice;


public class ClassFicationSortAdpter extends BaseAdapter {
    private Context mContext;
    private List<GoodSmallSortBean.GoodSmallSort> mLists ;
    private LayoutInflater layoutInflater;

    public ClassFicationSortAdpter(Context context,List<GoodSmallSortBean.GoodSmallSort> lists) {
        mContext = context;
        mLists = lists;
        layoutInflater=LayoutInflater.from(mContext);
    }

    @Override
    public int getCount() {
        return mLists != null ? mLists.size():0;
    }

    @Override
    public Object getItem(int i) {
        return mLists.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        ViewHolder holder=null;
        if(convertView == null){
            convertView= layoutInflater.inflate(R.layout.classfication_right_item,null);
            holder=new ViewHolder(convertView);
            convertView.setTag(holder);
            AutoUtils.auto(convertView);
        }else{
            holder= (ViewHolder) convertView.getTag();
        }


//        int width = (int)(TDevice.getScreenWidth()-360)/3;
//        LinearLayout.LayoutParams params2 = new LinearLayout.LayoutParams(width,width);
//        holder.cf_cur_img.setLayoutParams(params2);

//        String []nUrl=mLists.get(position).getImg().split("\\.");
//        StringBuffer buffer=new StringBuffer();
//        buffer.append(nUrl[0]).append("_360.").append(nUrl[1]);
        Glide.with(mContext).load(OKUtilAPI.imgBaseUrl+mLists.get(position).getImg())
                .asBitmap()
                .centerCrop()
                .into(holder.cf_cur_img);
//                .override(width,width)

//        GlideUitl.getGlide(mContext, OKUtilAPI.imgBaseUrl+mLists.get(position).getImg(),holder.cf_cur_img);
        holder.cf_cur_name.setText(mLists.get(position).getName());

        return convertView;
    }


    static class ViewHolder{
        @BindView(R.id.cf_cur_img)
        ImageView cf_cur_img;
        @BindView(R.id.cf_cur_name)
        TextView cf_cur_name;
        @BindView(R.id.lllp)
        LinearLayout lllp;

        public ViewHolder(View view){
            ButterKnife.bind(this,view);
        }
    }
}
